﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Sohar.Core
{
	public class WordMeaning
	{
		public WordMeaning(string value, WordClass @class)
		{
			this.Value = value;
			this.Class = @class;
		}

		public WordClass Class
		{
			get;
			set;
		}

		public string Value
		{
			get;
			set;
		}

		public void Save(int wordID)
		{
			SoharGateway gateway = new SoharGateway();
			gateway.InsertMeaning(this.Value, wordID, this.Class.ID);
		}

		public static WordMeaning[] GetByWord(int wordID)
		{
			List<WordMeaning> meanings = new List<WordMeaning>();
			SoharGateway gateway = new SoharGateway();
			using (IDataReader reader = gateway.GetMeaningByWord(wordID))
			{
				while (reader.Read())
				{
					meanings.Add(
						new WordMeaning(
							(string)reader["Value"], 
							WordClass.GetByID((int)reader["ClassID"])));
				}
			}

			return meanings.ToArray();
		}
	}
}
